﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using SFP;
using SFP.Animation2D;
using SFP.Audio;
using SFP.CollisionDetection;

namespace TestGame
{
    public class Block : Reaction
    {
        private LayerManager layerManager;
        private Player player;
        private ParticleSystem blockParticles;

        public Block(Player player, LayerManager layerManager)
        {
            this.layerManager = layerManager;
            this.player = player;
            this.blockParticles = new ParticleSystem();
        }

        public void loadBlockParticleSystem()
        {
            PSPreset preset = new PSPreset();
            preset.importXML(ContentLoader.LoadXML("presets\\block_debree.xml"));
            blockParticles.loadPreset(preset);

            layerManager.getLayer(2).addLayerObject(blockParticles);
        }

        public void updateBlockParticleSystem(double time)
        {
            blockParticles.update(time);
        }

        protected override void fromBeneath(CollisionInfo collisionInfo)
        {
            if (player.VelocityY <= 0) return;
            layerManager.getLayer(2).removeLayerObject(collisionInfo.GameObject);
            GameObjects.Blocks.Remove(collisionInfo.GameObject);

            AudioPlayer.play(Ressources.BREAK_BLOCK, true);

            ParticleSystem.Emitter emitter = blockParticles.GetEmitter();
            emitter.x = collisionInfo.GameObject.X + layerManager.getXScroll() + collisionInfo.GameObject.Width / 2;
            emitter.y = collisionInfo.GameObject.Y - layerManager.getYScroll() - collisionInfo.GameObject.Height / 2;
            emitter.emitt(4);
        }

        protected override void fromAbove(CollisionInfo collisionInfo)
        {
        }

        protected override void fromLeft(CollisionInfo collisionInfo)
        {
        }

        protected override void fromRight(CollisionInfo collisionInfo)
        {
        }

        protected override void touchesTop(CollisionInfo collisionInfo)
        {
        }

        protected override void touchesBottom(CollisionInfo collisionInfo)
        {
        }

        protected override void touchesLeft(CollisionInfo collisionInfo)
        {
        }

        protected override void touchesRight(CollisionInfo collisionInfo)
        {
        }
    }
}
